For positive integers $n$, define $S_n$ to be the minimum value of the sum
\[\sum_{k=1}^n \sqrt{(2k-1)^2+a_k^2},\]where $a_1,a_2,\ldots,a_n$ are positive real numbers whose sum is $17$. Find the unique positive integer $n$ for which $S_n$ is also an integer.
Answer: For $k = 0, 1, 2, \ldots, n,$ let $P_k = (k^2,a_1 + a_2 + \dots + a_k).$ Note that $P_0 = (0,0)$ and $P_n = (n^2,a_1 + a_2 + \dots + a_n) = (n^2,17).$

[asy]
unitsize(0.4 cm);

pair[] A, P;

P[0] = (0,0);
A[0] = (5,0);
P[1] = (5,1);
A[1] = (9,1);
P[2] = (9,3);

P[3] = (12,6);
A[3] = (15,6);
P[4] = (15,10);

draw(P[0]--A[0]--P[1]--cycle);
draw(P[1]--A[1]--P[2]--cycle);
draw(P[3]--A[3]--P[4]--cycle);
draw(P[0]--P[4],dashed);

label("$P_0$", P[0], W);
label("$P_1$", P[1], N);
label("$P_2$", P[2], N);
label("$P_{n - 1}$", P[3], W);
label("$P_n$", P[4], NE);
label("$a_1$", (A[0] + P[1])/2, E);
label("$a_2$", (A[1] + P[2])/2, E);
label("$a_n$", (A[3] + P[4])/2, E);

dot((21/2 - 0.5,9/2 - 0.5));
dot((21/2,9/2));
dot((21/2 + 0.5,9/2 + 0.5));
[/asy]

Then for each $k = 1, 2, \ldots, n,$ we have \[\begin{aligned} P_{k-1}P_k &= \sqrt{(k^2-(k-1)^2)+((a_1+a_2+\dots+a_{k-1}+a_{k})-(a_1+a_2+\dots+a_{k-1}))^2} \\ &= \sqrt{(2k-1)^2+a_k^2}, \end{aligned}\]so that $S_n$ is the minimum value of the sum $P_0P_1 + P_1P_2 + \dots + P_{n-1}P_n.$ By the triangle inequality, \[P_0P_1 + P_1P_2 + \dots + P_{n-1}P_n \ge P_0P_n = \sqrt{n^4 + 289}.\]Furthemore, equality occurs when all the $P_i$ are collinear, so $S_n = \sqrt{n^4+289}$ for each $n.$

It remains to find the $n$ for which $S_n$ is an integer, or equivalently, $n^4+289$ is a perfect square. Let $n^4+289=m^2$ for some positive integer $m.$ Then $m^2-n^4=289,$ which factors as \[(m-n^2)(m+n^2) = 289.\]Since $n^2$ is positive and $289 = 17^2,$ the only possibility is $m-n^2=1$ and $m+n^2=289,$ giving $m = 145$ and $n^2 = 144.$ Thus $n = \sqrt{144} = \boxed{12}.$